﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace OpenPhotoAlbum.Maintainance
{
	public partial class Default : AlbumPage
	{
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			linkBtnClearCache.Click += new EventHandler(linkBtnClearCache_Click);
		}

		protected void linkBtnClearCache_Click(object sender, EventArgs e)
		{
			BusinessLogics.CacheManager.Instance.ClearCache();
			OpenPhotoAlbum.Controls.JsMsgBox.Show(this, "All cached data is cleared");
		}

		protected override void AppendSiteMapNodes(OpenPhotoAlbum.Controls.AlbumSiteMapProvider provider)
		{
			base.AppendSiteMapNodes(provider);

			provider.AppendSiteMapNode("Maintainance Console", RawUrl);
		}

		protected void linkBtnLoginAs_Click(object sender, EventArgs e)
		{
			string userName = hfUserName.Value;
			if (string.IsNullOrEmpty(userName)) { return; }

			DbAccess.User user = BusinessLogics.UserManager.Instance.GetUser(userName);
			if (user == null) { return; }

			userName = user.UserName;
			BusinessLogics.ActionManager.Instance.AddLoginSuccess(userName);
			FormsAuthentication.SetAuthCookie(userName, false);
			Response.Redirect(Links.MyHome);
		}
	}
}
